﻿using System;
using System.Globalization;
using System.Windows.Data;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace MSFforAgileSoftwareDevelopmentv50.Converters
{
    class EstimateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var workItem = value as WorkItem;
            string fieldName = "Original Estimate";
            if (workItem != null)
            {
                object estimate = workItem.Fields[fieldName].Value;
                if (estimate != null)
                {
                    object estimateString = workItem.Fields[fieldName].Value.ToString();
                    decimal estimateValue = System.Convert.ToDecimal(estimateString);

                    return estimateValue / 8; ;
                }
            }

            return "-";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}